import java.util.*;
// https://www.acwing.com/problem/content/2/  01背包问题1
class bag01
{
    public static void main(String[] args)
    {
        Scanner sc  = new Scanner(System.in);
        int n = sc.nextInt();
        int v = sc.nextInt();
        // 从前i个物品中选且体积小于等于j的最大价值
        int [] dp = new int[v + 2];
        int [] v1 = new int[n+1];
        int [] w1 = new int[n+1];
        for(int i = 1 ; i <= n ; i ++)
        {
            v1[i] = sc.nextInt();
            w1[i] = sc.nextInt();
        }
        for(int i = 1 ; i <= n ; i ++)
        {
            
            for(int j = v ; j > 0 ; j --)
            {
               // dp[j] = dp[j];
                if(v1[i] <= j){
                    dp[j] = Math.max(dp[j],dp[j-v1[i]] + w1[i]);
                }
            }
        }
        System.out.print(dp[v]);
       
    }
    
}